/**
 * @file Define the dashboard controller
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */
const WebBaseController = require('./web-base-controller');

const {SystemServices}  = require('../../constants');

/**
 * The class BaseController
 * 
 * @description 
 * 
 * @class DashboardController
 * @extends {BaseController}
 */
class DashboardController extends WebBaseController {
    
    get wallService() {
        if (!this._wallService) {
            this._wallService = this.getSystemService(SystemServices.WALL_SERVICE);
        }

        return this._wallService;
    }

    get userService() {
        if (!this._userService) {
            this._userService = this.getSystemService(SystemServices.USER_SERVICE);
        }
        return this._userService;
    }

    get name() {
        return "DashboardController";
    }
    
    get handlersPath() {
        return 'dashboard';
    }

    /**
     * Wrap the Wall Service's saveOrUpdateAccount method
     * 
     * @name saveOrUpdateAccount
     * @param {String} userId - The userId
     * @param {Object} account - The user account information
     * 
     * @returns {void}
     */
    saveOrUpdateAccount(userId, account, parentCallback) {
        this.wallService.saveOrUpdateAccount(userId, account, (error, data) => {
            parentCallback(error, data);
        });
    }

    /**
     * Wrap the User Service's getPlanInfo method
     * 
     * @name getPlanInfo
     * @param {String} userId - The user id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getPlanInfo(userId, parentCallback) {
        this.userService.getPlanInfo(userId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the Wall Service's getOfficialAccountsByUserId method
     * 
     * @name getOfficialAccountsByUserId
     * @param {String} userId - The user id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getOfficialAccountsByUserId(userId, parentCallback) {
        this.wallService.getOfficialAccountsByUserId(userId, (data) => {
            parentCallback(data);
        });
    }

    /**
     * Wrap the Wall Service's getManagedOfficialAccountsByUserIdAndType method
     * 
     * @name getManagedOfficialAccountsByUserIdAndType
     * @param {String} userId - The user id
     * @param {String} socialType - The social type
     * 
     * @returns {void}
     */
    getManagedOfficialAccountsByUserIdAndType(userId, socialType, parentCallback) {
        this.wallService.getManagedOfficialAccountsByUserIdAndType(userId, socialType, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the Wall Service's verifyPassword method
     * 
     * @name getSalesByIdentifier
     * @param {String} userId - The user id
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getSalesByIdentifier(salesId, parentCallback) {
        //TODO: 
        this.wallService.getSalesByIdentifier(salesId, (data) => {
            parentCallback(data);
        });
    }

    /**
     * Wrap the Wall Service's verifyPassword method
     * 
     * @name verifyPassword
     * @param {String} email - The email address
     * @param {String} password - The password
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    verifyPassword(email, password, parentCallback) {
        this.wallService.verifyPassword(email, password, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Get image URL with CDN host
     * 
     * @name getCDNImageURL
     * @param {String} image - The original image URL
     * 
     * @returns {String}
     */
    getCDNImageURL(image) {
        return this.wallService.getCDNImageURL(image);
    }

    saveOrUpdateSystemUser(selfServiceUserId, internalOrderId, initialPlanId, name, email, password, refs, locale, thirdPartyId, parentCallback) {
        this.wallService.saveOrUpdateSystemUser(selfServiceUserId, internalOrderId, initialPlanId, name, email, password, refs, locale, thirdPartyId, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrapper the WallService's getWallsByUserId function
     * 
     * @name getWallsByUserId
     * @param {String} userId - The user id
     * @param {String} parentCallback - The callback function
     * 
     * @returns {void}
     */
    getWallsByUserId(userId, parentCallback) {
        this.wallService.getWallsByUserId(userId, (walls) => {
            parentCallback(walls);
        });
    }
}

exports.DashboardController = DashboardController;